const { DataTypes } = require('sequelize/dist');
const sequelize = require('../config/sequelize');
const Topic = require('./topic');
const User = require('./user');

const Comment = sequelize.define('comments', {
  id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    primaryKey: true,
    autoIncrement: true,
  },
  content: {
    type: DataTypes.STRING,
  },
  fromuser: {
    type: DataTypes.STRING,
  },
  touser: {
    type: DataTypes.STRING,
  },
  fromId: {
    type: DataTypes.INTEGER,
    references: {
      model: User,
      key: 'user_id',
    },
  },
  toId: {
    type: DataTypes.INTEGER,
    references: {
      model: User,
      key: 'user_id',
    },
  },
  topic_id: {
    type: DataTypes.INTEGER,
    references: {
      model: Topic,
      key: 'topic_id',
    },
  },
  replayId: {
    type: DataTypes.INTEGER,
    allowNull: true,
  },
});

module.exports = Comment;
